﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class Posts_Header : BaseUserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataBind();
        }
    }

    public override void DataBind()
    {
        if (Page is BasePostPage)
        {
            SetPost(((BasePostPage)Page).CurrentPost);
        }
        var menu = tabHeading.Tabs.Where(x => x.NavigateUrl.EndsWith("/Menu.aspx")).SingleOrDefault();
        if (menu != null)
        {
            menu.Visible = Page.AcmsContext.Site.UseMenus;
        }
        var topic = tabHeading.Tabs.Where(x => x.NavigateUrl.EndsWith("/Topic.aspx")).SingleOrDefault();
        if (topic != null)
        {
            topic.Visible = Page.AcmsContext.Site.UseMenus;
        }
    }

    public void SetPost(Acms.Bll.Post post)
    {
        if (post != null)
        {
            foreach (RadTab tab in tabHeading.Tabs)
            {
                tab.NavigateUrl = ((BasePostPage)Page).AppendQueryStringParameters(tab.NavigateUrl);
                if (tab.NavigateUrl.StartsWith(Page.Request.AppRelativeCurrentExecutionFilePath))
                {
                    tab.Selected = true;
                }
            }
        }
    }


    private string siteVersion;
    protected override object SaveViewState()
    {
        return base.SaveViewState();
    }
    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
    }


    public void UpdateHeader()
    {
        DataBind();
    }

}
